package com.zmn.plat.services.impl.orderconfig.track;

import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.zmn.common.dto.StatusDTO;
import com.zmn.common.utils.date.DateUtil;
import com.zmn.plat.model.entity.orderconfig.track.OrderTrack;
import com.zmn.plat.model.entity.orderconfig.track.OrderTrackQuery;
import com.zmn.plat.model.vo.orderconfig.track.OrderTrackVO;
import com.zmn.plat.persistence.interfaces.orderconfig.track.OrderTrackDao;
import com.zmn.plat.services.interfaces.orderconfig.track.OrderTrackService;

/**
 * @author tanbiao
 * @description
 * @modifier
 * @since 2020/11/19 18:06
 **/
@Service
public class OrderTrackServiceImpl implements OrderTrackService {
    @Resource
    private OrderTrackDao orderTrackDao;

    @Override
    public OrderTrack findByKey(Integer trackId) {
        return orderTrackDao.findByKey(trackId);
    }

    @Override
    public List<OrderTrackVO> listByKeys(List<Integer> ids) {
        return orderTrackDao.listByKeys(ids);
    }

    @Override
    public Integer findMaxSort() {
        return orderTrackDao.findMaxSort();
    }

    @Override
    public List<OrderTrackVO> listPageByQuery(OrderTrackQuery query) {
        int count = countByQuery(query);
        query.setTotalCount(count);
        return orderTrackDao.listPageByQuery(query);
    }

    @Override
    public List<OrderTrack> listByQuery(OrderTrackQuery query) {
        return orderTrackDao.listByQuery(query);
    }

    @Override
    public Integer countByQuery(OrderTrackQuery query) {
        return orderTrackDao.countByQuery(query);
    }

    @Override
    public Integer updateByKey(OrderTrack orderTrack) {
        orderTrack.setUpdateTime(new Date());
        return orderTrackDao.updateByKey(orderTrack);
    }

    @Override
    public Integer updateStatusBatch(List<Integer> categoryIds, Integer status, String staffName) {
        StatusDTO dto = new StatusDTO();
        dto.setIds(categoryIds);
        dto.setStatus(status);
        dto.setUpdater(staffName);
        dto.setUpdateTime(new Date());
        return orderTrackDao.updateStatusBatch(dto);
    }

    @Override
    public Integer updateSortKey(Integer trackId, Integer sort, String staffName) {
        OrderTrack cancelCategory = new OrderTrack();
        cancelCategory.setTrackId(trackId);
        cancelCategory.setSort(sort);
        cancelCategory.setUpdateTime(new Date());
        cancelCategory.setUpdater(staffName);
        cancelCategory.setUpdateTime(new Date());
        return orderTrackDao.updateSortKey(cancelCategory);
    }

    @Override
    public Integer insert(OrderTrack orderTrack) {
        Date now = DateUtil.getNow();
        orderTrack.setUpdateTime(now);
        orderTrack.setCreateTime(now);
        return orderTrackDao.insert(orderTrack);
    }

    @Override
    public Integer deleteByKey(Integer id) {
        return orderTrackDao.deleteByKey(id);
    }
}
